/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kallsonys.object;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author allan
 */
@Entity
@Cacheable(false)
@Table(name = "CUSTOMER")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c"),
    @NamedQuery(name = "Customer.findByCustomerid", query = "SELECT c FROM Customer c WHERE c.customerid = :customerid"),
    @NamedQuery(name = "Customer.findByCustomerfirstname", query = "SELECT c FROM Customer c WHERE c.customerfirstname = :customerfirstname"),
    @NamedQuery(name = "Customer.findByCustomerlastname", query = "SELECT c FROM Customer c WHERE c.customerlastname = :customerlastname"),
    @NamedQuery(name = "Customer.findByCustomeremail", query = "SELECT c FROM Customer c WHERE c.customeremail = :customeremail"),
    @NamedQuery(name = "Customer.findByCustomerpassword", query = "SELECT c FROM Customer c WHERE c.customerpassword = :customerpassword"),
    @NamedQuery(name = "Customer.findByCustomertype", query = "SELECT c FROM Customer c WHERE c.customertype = :customertype"),
    @NamedQuery(name = "Customer.findByCustomerdocument", query = "SELECT c FROM Customer c WHERE c.customerdocument = :customerdocument")})
public class Customer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @GeneratedValue(generator="CustomerSeq")
    @SequenceGenerator(name="CustomerSeq",sequenceName="SEQ_CUSTOMER",initialValue=1, allocationSize=1)
    @Column(name = "CUSTOMERID")
    private Long customerid;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "CUSTOMERFIRSTNAME")
    private String customerfirstname;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "CUSTOMERLASTNAME")
    private String customerlastname;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "CUSTOMEREMAIL")
    private String customeremail;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "CUSTOMERPASSWORD")
    private String customerpassword;
    @Basic(optional = false)
    @NotNull
    @Column(name = "CUSTOMERTYPE")
    private BigInteger customertype;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "CUSTOMERDOCUMENT")
    private String customerdocument;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "customerid")
    private List<Creditcard> creditcardList;
    @JoinColumn(name = "LASTUSEDCREDITCARDID", referencedColumnName = "CREDITCARDID")
    @ManyToOne
    private Creditcard lastusedcreditcardid;
    @JoinColumn(name = "LASTUSEDADDRESSID", referencedColumnName = "ADDRESSID")
    @ManyToOne
    private Address lastusedaddressid;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "customerid")
    private List<Address> addressList;

    public Customer() {
    }

    public Customer(Long customerid) {
        this.customerid = customerid;
    }

    public Customer(Long customerid, String customerfirstname, String customerlastname, String customeremail, String customerpassword, BigInteger customertype, String customerdocument) {
        this.customerid = customerid;
        this.customerfirstname = customerfirstname;
        this.customerlastname = customerlastname;
        this.customeremail = customeremail;
        this.customerpassword = customerpassword;
        this.customertype = customertype;
        this.customerdocument = customerdocument;
    }

    public Long getCustomerid() {
        return customerid;
    }

    public void setCustomerid(Long customerid) {
        this.customerid = customerid;
    }

    public String getCustomerfirstname() {
        return customerfirstname;
    }

    public void setCustomerfirstname(String customerfirstname) {
        this.customerfirstname = customerfirstname;
    }

    public String getCustomerlastname() {
        return customerlastname;
    }

    public void setCustomerlastname(String customerlastname) {
        this.customerlastname = customerlastname;
    }

    public String getCustomeremail() {
        return customeremail;
    }

    public void setCustomeremail(String customeremail) {
        this.customeremail = customeremail;
    }

    public String getCustomerpassword() {
        return customerpassword;
    }

    public void setCustomerpassword(String customerpassword) {
        this.customerpassword = customerpassword;
    }

    public BigInteger getCustomertype() {
        return customertype;
    }

    public void setCustomertype(BigInteger customertype) {
        this.customertype = customertype;
    }

    public String getCustomerdocument() {
        return customerdocument;
    }

    public void setCustomerdocument(String customerdocument) {
        this.customerdocument = customerdocument;
    }

    @XmlTransient
    public List<Creditcard> getCreditcardList() {
        return creditcardList;
    }

    public void setCreditcardList(List<Creditcard> creditcardList) {
        this.creditcardList = creditcardList;
    }

    public Creditcard getLastusedcreditcardid() {
        return lastusedcreditcardid;
    }

    public void setLastusedcreditcardid(Creditcard lastusedcreditcardid) {
        this.lastusedcreditcardid = lastusedcreditcardid;
    }

    public Address getLastusedaddressid() {
        return lastusedaddressid;
    }

    public void setLastusedaddressid(Address lastusedaddressid) {
        this.lastusedaddressid = lastusedaddressid;
    }

    @XmlTransient
    public List<Address> getAddressList() {
        return addressList;
    }

    public void setAddressList(List<Address> addressList) {
        this.addressList = addressList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (customerid != null ? customerid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        if ((this.customerid == null && other.customerid != null) || (this.customerid != null && !this.customerid.equals(other.customerid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return customerdocument + "-"  + customerfirstname+ "-" +customerlastname;
    }
    
}
